package btree;

import exceptions.*;
import diskmgr.Page;
import global.PageId;
import global.SystemDefs;
import heap.HFPage;

public class BTreeHeaderPage extends HFPage {
	private PageId root;
	private int keyType;
	private int keySize;
	private String fileName;
	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public BTreeHeaderPage(PageId pageno) 
		    throws ConstructPageException
		    { 
		      super();
		      try {
			
			SystemDefs.JavabaseBM.pinPage(pageno, this, false/*Rdisk*/); 
		      }
		      catch (Exception e) {
			throw new ConstructPageException(e, "pinpage failed");
		      }
		    }
		  
		  public PageId getRoot() {
		return root;
	}

	public void setRoot(PageId root) {
		this.root = root;
	}

	public int getKeyType() {
		return keyType;
	}

	public void setKeyType(int keyType) {
		this.keyType = keyType;
	}

	public int getKeySize() {
		return keySize;
	}

	public void setKeySize(int keySize) {
		this.keySize = keySize;
	}

		/**associate the SortedPage instance with the Page instance */
		  public BTreeHeaderPage(Page page) {
		    
		    super(page);
		  }  
		  
		  
		  /**new a page, and associate the SortedPage instance with the Page instance
		   */
		  public BTreeHeaderPage( ) 
		    throws ConstructPageException
		    {
		      super();
		      try{
			Page apage=new Page();
			PageId pageId=SystemDefs.JavabaseBM.newPage(apage,1);
			if (pageId==null) 
			  throw new ConstructPageException(null, "new page failed");
			this.init(pageId, apage);
			
		      }
		      catch (Exception e) {
			throw new ConstructPageException(e, "construct header page failed");
		      }
		    }  
		  
		
}
